package com.hui.platform.falseworkapi.common.security.configurer;

import com.hui.platform.falseworkapi.common.security.base.IBasicHttpSecurityConfigurer;
import com.hui.platform.falseworkapi.common.security.constant.SecurityConstant;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.stereotype.Component;

/**
 * Swagger 安全路径配置
 *
 * @author Peng
 * @date 2019/12/12
 */
@Component
public class SwaggerBasicHttpSecurityConfigurer implements IBasicHttpSecurityConfigurer {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        //选择匹配器
        http.requestMatchers().antMatchers(getSwaggerUris());
        //权限解决器
        http.authorizeRequests().antMatchers(getSwaggerUris()).hasRole(SecurityConstant.SYSTEM_DEV);
    }

    private String[] getSwaggerUris() {
        //SwaggerURL数组
        return new String[]{
                "/doc.html",
                "/swagger-ui.html",
                "/v2/**",
                "/swagger-resources/**",
        };
    }
}
